<?php !defined('IN_ONEZ') && exit('Access Denied');?>
<?php

/*
数据库说明
$db['site']='mysql://数据库账号:数据库密码@localhost:3306/数据库名?tablepre=表名前缀&charset=数据库编码';

示例
$db['site']='mysql://root:123456@localhost:3306/wordpress?tablepre=wp_&charset=utf8';
*/

include(dirname(ONEZ_ROOT).'/data/sql_config.php');
include(dirname(ONEZ_ROOT).'/data/bbscache/config.php');
#改成您自己的
$dbhost2 = $dbhost;//数据库地址
$dbuser2 = $dbuser;//数据库用户名
$dbpass2 = $dbpw;//数据库密码
$dbname2 = $dbname;//数据库名
$charset2 = $charset;
$db['site']="mysql://$dbuser:$dbpw@$dbhost:3306/$dbname?tablepre=$PW&charset=$charset";
function synlogin(){
  global $data;
  $uid=$data['uid'];
  
  $T=D('site')->one("members","uid,username,password,safecv","uid='$uid'");
  if(!$T)exit('登录超时');
  $winduid=$T['uid'];
  $windpwd=md5($_SERVER['HTTP_USER_AGENT'].$T['password'].$GLOBALS['db_hash']);
  $safecv=$T['safecv'];
  $winduser=_StrCode(("$winduid\t$windpwd\t$safecv"),"ENCODE");
  $GLOBALS['cookiepre'] = substr(md5($GLOBALS['db_sitehash']),0,5).'_';
  
  _cookie('winduser',$winduser,31536000);
  _cookie('ck_info',$GLOBALS['db_ckpath']."\t".$GLOBALS['db_ckdomain'],0);
  _cookie('lastvisit','',0);
  
  exit('<script>location.href="'.BACKURL.'";</script>');
}
function _StrCode($string,$action='ENCODE'){
	$action != 'ENCODE' && $string = base64_decode($string);
	$code = '';
	$key  = substr(md5($_SERVER['HTTP_USER_AGENT'].$GLOBALS['db_hash']),8,18);
	$keylen = strlen($key); $strlen = strlen($string);
	for ($i=0;$i<$strlen;$i++) {
		$k		= $i % $keylen;
		$code  .= $string[$i] ^ $key[$k];
	}
	return ($action!='DECODE' ? base64_encode($code) : $code);
}
function chklogin(){
  global $data,$usr,$pwd;
  
  $pwd=md5($pwd);
  $T=D('site')->one("members","*","username='$usr' and password='$pwd'");
  !$T && ero('用户名或密码不正确');
  
  $uid=$T['uid'];
  
  return $uid;
}